package com.eui.arch.util
{
	import flash.events.EventDispatcher;
	import flash.utils.Dictionary;


	/**
	 * PMContext is to cache a managedPM, make it easier to access
	 * @author David Zhang
	 */
	public class PMContext
	{
		private static var _instance:PMContext;

		public static function getInstance():PMContext
		{
			if (_instance == null)
			{
				_instance = new PMContext(new PrivateClass());
			}
			return _instance;
		}

		public function PMContext(privateClass:PrivateClass)
		{
			if (privateClass == null)
			{
				throw new Error("PMContext cannot be instantiated, use getInstance()");
			}
		}

		private var pmDictionary:Dictionary = new Dictionary();

		public function putPM(pmName:String, pm:ManagedPM):void
		{
			trace("Put ManagedPM " + pmName);
			pmDictionary[pmName] = pm;
		}

		public function getPM(pmName:String):ManagedPM
		{
			trace("Get ManagedPM " + pmName);
			var result:ManagedPM = pmDictionary[pmName];
			if (result == null)
			{
				throw new Error("PM for " + pmName + " doesn't exist!");
			}
			return result;
		}

		public function removePM(pmName:String):void
		{
			trace("Remove ManagedPM " + pmName);
			pmDictionary[pmName] = null;
		}
	}
}

internal class PrivateClass
{
}
